package com.dap.cas.controller;

import com.dap.cas.config.SpringCasConfigProperties;
import com.dap.cas.util.CASUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @description: 类描述
 * @author: Fesine
 * @createTime:2017/12/26
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2017/12/26
 */
@Controller
public class HomeController {
    /**
     * @param service http://client1.fesine.com:8080/index.html
     * @return
     */
    @Autowired
    SpringCasConfigProperties casConfigProperties;
    @GetMapping("/home")
    public String home(@RequestParam String service) {
        return "redirect:" + service;
    }

    @GetMapping("/logout")
    public String logout(@RequestParam String service) {
        return "redirect:" + casConfigProperties.getCasServerLogoutUrl()+"?service="+ service;
    }

    @GetMapping("/userName")
    @ResponseBody
    public String userName(HttpServletRequest request) {
        return CASUtil.getAccountNameFromCas(request);
    }
}
